package cn.com.huzo.webapp.controller.purchase;

import cn.com.huzo.model.entities.purchase.ReportMaterialQueryInPoEntity;
import cn.com.huzo.model.entities.purchase.ReportOpenNotesPayabledEntity;
import cn.com.huzo.model.entities.purchase.ReportOpenPoEntity;
import cn.com.huzo.model.entities.purchase.ReportPoCostPerStyleEntity;
import cn.com.huzo.model.entities.purchase.ReportPoStatisticsEntity;
import cn.com.huzo.model.entities.purchase.ReportPoSurchargeEntity;
import cn.com.huzo.service.purchase.ReportMaterialQueryInPoManager;
import cn.com.huzo.service.purchase.ReportOpenNotesPayabledManager;
import cn.com.huzo.service.purchase.ReportOpenPoManager;
import cn.com.huzo.service.purchase.ReportPoCostPerStyleManager;
import cn.com.huzo.service.purchase.ReportPoStatisticsManager;
import cn.com.huzo.service.purchase.ReportPoSurchargeManager;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.List;
import java.util.Map;
import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.ModelAndView;

/**
 * 采购相关统计、分析、报告
 *
 * @author 吴旭
 */
@Controller
@RequestMapping(value = "/purchase/report")
public class PurchaseReportController {

    // <editor-fold defaultstate="collapsed" desc="属性">
    @Resource(name = "ReportPoSurchargeManager")
    private ReportPoSurchargeManager _manager_po_surcharge;

    @Resource(name = "ReportMaterialQueryInPoManager")
    private ReportMaterialQueryInPoManager _manager_material_query_in_po;

    @Resource(name = "ReportPoStatisticsManager")
    private ReportPoStatisticsManager _manager_po_statistics;

    @Resource(name = "ReportOpenPoManager")
    private ReportOpenPoManager _manager_open_po;

    @Resource(name = "ReportOpenNotesPayabledManager")
    private ReportOpenNotesPayabledManager _manager_open_notes_payabled;

    @Resource(name = "ReportPoCostPerStyleManager")
    private ReportPoCostPerStyleManager _manager_pocost_per_style;
    // </editor-fold>

    // <editor-fold defaultstate="collapsed" desc="画面处理部分">
    /**
     * 订单附加费查询画面
     * <p>
     * @param request
     * @return
     * @throws java.lang.Exception
     */
    @RequestMapping("/surcharge/list.html")
    public ModelAndView redirectPoSurChargesWnd(HttpServletRequest request) throws Exception {
        int thisYear = Calendar.getInstance().get(Calendar.YEAR); // 得到今年
        List<Integer> yearList = new ArrayList();
        thisYear = thisYear - 5;
        for (int i = 0; i < 11; i++) {
            yearList.add(thisYear);
            thisYear = thisYear + 1;
        }

        ModelAndView view = new ModelAndView();
        view.addObject("YearList", yearList);
        view.setViewName("purchase.report_po_surcharge.list.def");
        return view;
    }

    /**
     * 采购查料表查询画面
     * <p>
     * @param request
     * @return
     * @throws java.lang.Exception
     */
    @RequestMapping("/material_query_in_po/list.html")
    public ModelAndView redirectPoMaterialCheckWnd(HttpServletRequest request) throws Exception {
        ModelAndView view = new ModelAndView();
        view.setViewName("purchase.report_material_query_in_po.list.def");
        return view;
    }

    /**
     * 跳转到采购合同统计报表画面
     * <p>
     * @param request
     * @return
     * @throws java.lang.Exception
     */
    @RequestMapping("/po_statistics/list.html")
    public ModelAndView redirectReportPoStatisticsWnd(HttpServletRequest request) throws Exception {
        ModelAndView view = new ModelAndView();
        view.setViewName("purchase.report_po_statistics.list.def");
        return view;
    }

    /**
     * 跳转到(采购)下单一览表一览画面（主辅料），目的查看调达表还有哪些被遗漏的材料
     * <p>
     * @param request
     * @return
     * @throws java.lang.Exception
     */
    @RequestMapping("/open_po/list.html")
    public ModelAndView redirectReportOpenPotWnd(HttpServletRequest request) throws Exception {
        ModelAndView view = new ModelAndView();
        view.setViewName("purchase.report_open_po.list.def");
        return view;
    }

    /**
     * 跳转到未对账信息，目的查看还有订单入库了没被对账
     * <p>
     * @param request
     * @return
     * @throws java.lang.Exception
     */
    @RequestMapping("/open_notes_payabled/list.html")
    public ModelAndView redirectReportOpenNotesPayabledWnd(HttpServletRequest request) throws Exception {
        ModelAndView view = new ModelAndView();
        view.setViewName("purchase.report_open_notes_payabled.list.def");
        return view;
    }

    /**
     * 跳转到款采购成本统计表报表画面
     * <p>
     * @param request
     * @return
     * @throws java.lang.Exception
     */
    @RequestMapping("/pocost_per_style/list.html")
    public ModelAndView redirectReportPoCostPerStyleWnd(HttpServletRequest request) throws Exception {
        ModelAndView view = new ModelAndView();
        view.setViewName("purchase.report_pocost_per_style.list.def");
        return view;
    }
    // </editor-fold>

    // <editor-fold defaultstate="collapsed" desc="数据处理部分">
    /**
     * 根据条件取得订单附加费数据。
     *
     * @param criterion 搜索条件
     * @return 订单附加费数据。
     * @throws java.lang.Exception
     */
    @RequestMapping(value = "/surcharge/fetchAll.html",
            method = RequestMethod.POST)
    public @ResponseBody
    List<ReportPoSurchargeEntity> fetchAll(@RequestBody final Map<String, Object> criterion) throws Exception {
        return _manager_po_surcharge.fetchReportData(criterion);
    }

    /**
     * 根据条件取得采购查料一览表数据。
     *
     * @param criterion 搜索条件
     * @return 订单附加费数据。
     * @throws java.lang.Exception
     */
    @RequestMapping(value = "/material_query_in_po/fetchAll.html",
            method = RequestMethod.POST)
    public @ResponseBody
    List<ReportMaterialQueryInPoEntity> fetchAllMaterialQueryInPo(@RequestBody final Map<String, Object> criterion) throws Exception {
        return _manager_material_query_in_po.fetchReportData(criterion);
    }

    /**
     * 根据条件取得采购合同统计报表数据。
     *
     * @param criterion 搜索条件
     * @return 采购合同统计报表数据。
     * @throws java.lang.Exception
     */
    @RequestMapping(value = "/po_statistics/fetchAll.html",
            method = RequestMethod.POST)
    public @ResponseBody
    List<ReportPoStatisticsEntity> fetchAllReportPoStatistics(@RequestBody final Map<String, Object> criterion) throws Exception {
        return _manager_po_statistics.fetchReportData(criterion);
    }

    /**
     * 采购下单情况。
     *
     * @param criterion 搜索条件
     * @return 采购下单与调达的对比表。
     * @throws java.lang.Exception
     */
    @RequestMapping(value = "/open_po/fetchAll.html",
            method = RequestMethod.POST)
    public @ResponseBody
    List<ReportOpenPoEntity> fetchAllReportOpenPo(@RequestBody final Map<String, Object> criterion) throws Exception {
        return _manager_open_po.fetchReportData(criterion);
    }

    /**
     * 未对账信息。
     *
     * @param criterion 搜索条件
     * @return 未对账信息。
     * @throws java.lang.Exception
     */
    @RequestMapping(value = "/open_notes_payabled/fetchAll.html",
            method = RequestMethod.POST)
    public @ResponseBody
    List<ReportOpenNotesPayabledEntity> fetchAllReportOpenNotesPayabled(@RequestBody final Map<String, Object> criterion) throws Exception {
        return _manager_open_notes_payabled.fetchReportData(criterion);
    }

    /**
     * 款采购成本统计表。
     *
     * @param criterion 搜索条件
     * @return 款采购成本统计表。
     * @throws java.lang.Exception
     */
    @RequestMapping(value = "/pocost_per_style/fetchAll.html",
            method = RequestMethod.POST)
    public @ResponseBody
    List<ReportPoCostPerStyleEntity> fetchAllReportPoCostPerStyle(@RequestBody final Map<String, Object> criterion) throws Exception {
        return _manager_pocost_per_style.fetchReportData(criterion);
    }
    // </editor-fold>
}
